package com.example.xueshen.common.component;

import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Objects;

public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Object userName = request.getSession().getAttribute("loginUserName");
        if(Objects.nonNull(userName)){//工具类Objects判定userName不为null
            return true;
        }
        request.setAttribute("login_msg","权限不够，请重新登录");
        request.getRequestDispatcher("/index.html").forward(request,response);
        return false;
    }


}
